<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理后台</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="/favicon.ico" type="image/x-icon" rel="shortcut icon" />
    <!-- Bootstrap 3.3.4 -->
    <link href="/public/admin/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/public/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/public/admin/css/animate.css" rel="stylesheet">
    <link href="/public/admin/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="/public/admin/css/style.css?v=4.0.0" rel="stylesheet">
    <link href="/public/admin/css/ratuo.css" rel="stylesheet">

    <script src="/public/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/admin/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="/public/admin/js/common.js"></script>
    <script src="/public/admin/js/plugins/layer/layer.min.js"></script>
    <script src="/public/admin/js/myAjax.js"></script>
    <script src="/public/admin/js/jquery.validate.js"></script>
    
    <link href="/public/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <script src="/public/admin/js/plugins/iCheck/icheck.min.js"></script>

    <script src="/public/admin/js/article.js"></script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>文章列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">  
                                    <div class="panel-body">
                                        <form id="formSearch" method="get" action="{:url('article/articleList')}" class="form-horizontal form-inline">
                                            <b>文章栏目：</b>
                                            <select class="form-control kind_id" name="kind_id">
                                                <option value="">所有栏目</option>
                                                <?php echo $cat_select ?>
                                            </select>
                                            <label class="control-label">关键字：</label>
                                            <input type="text" placeholder="标题关键字" name="keyword" id="keyword" value="{$keyword}" class="form-control">
                                            <button type="submit" style="margin-left:30px" class="btn btn-primary">查询</button>
                                            <button onclick="window.location.href=location.href;"  class="btn btn-primary " style="float: right; margin-top: 10px;margin-right:10px;"><i class="glyphicon glyphicon-refresh"></i>刷新</button>
                                            <button onclick="openYemian('/index.php/Admin/Article/article','添加文章')" type="button" class="btn btn-primary" style="float: right;margin-right:10px; margin-top: 10px;"><i class="fa fa-plus"></i>添加</button>
                                        </form>
                                    </div>
                                </div>
                                <div class="box-body">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div id="ajaxList">
                                                <form method="post" enctype="multipart/form-data" id="form-order">
                                                <table class="table table-bordered table-hover">
                                                    <thead>
                                                        <tr>
                                                            <th style="width: 1px;"><input type="checkbox" onclick="$('input[name*=\'ids\']').prop('checked', this.checked);"></th>
                                                            <th>文章ID</th>
                                                            <th>所属类别</th>
                                                            <th>文章标题</th>
                                                            <th>文章点击数</th> 
                                                            <th>文章序号</th> 
                                                            <th>添加时间</th>
                                                            <th>操作</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody id="ajaxList"> 
                                                        {if empty($list)}
                                                            <tr>
                                                                <td colspan="7" align="center">暂无数据</td>
                                                            </tr>
                                                        {/if}
                                                        {foreach name="list" item="vo" key="k" }
                                                          <tr role="row">
                                                            <td><input type="checkbox" name="ids[]" value="{$vo.article_id}" onclick="attrBg(this)"></td>
                                                            <td>{$vo.article_id}</td>
                                                            <td>{$cats[$vo['kind_id']]['kind_name']}</td>
                                                            <td><a href="{:url('home/index/article',array('aid'=>$vo['article_id']))}" title="点击预览" target="_block">{$vo.title|getSubstr=0,33}&nbsp;
                                                            {eq name="vo.is_home" value="1"}<font color="red">[首页]</font>{/eq}
                                                            {eq name="vo.is_hot" value="1"}<font color="red">[热点]</font>{/eq}
                                                            {eq name="vo.is_tj" value="1"}<font color="red">[新鲜事]</font>{/eq}
                                                            </a></td>
                                                            <td>{$vo.click}</td> 
                                                            <td><input type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onchange="updateSort('article','article_id','{$vo.article_id}','sort_order',this)" size="4"  value="{$vo.sort_order}" /></td> 
                                                            <td>{$vo.add_time}</td>
                                                            <td>
                                                              <a class="btn btn-primary" href="javascript:;" title="编辑" onclick="openYemian('/index.php/Admin/Article/article/act/edit/article_id/{$vo.article_id}','编辑文章内容')"><i class="fa fa-pencil"></i></a>
                                                              <a class="btn btn-danger" href="javascript:void(0)" title="删除" data-url="{:url('Article/aticleHandle')}" data-id="{$vo.article_id}" onclick="delarticle(this,'确定把该文章加入回收站？',{$vo.article_id},'/index.php/Admin/Article/articleReback')"><i class="fa fa-trash-o"></i></a>
                                                              <a href="javascript:void(0)" data-toggle="tooltip" class="btn btn-info" data-original-title="复制文章" title="复制文章" onclick="copyarticle(this,'确定复制该文章吗？',{$vo.article_id},'/index.php/Admin/Article/articlecopy')"><i class="fa fa-copy"></i></a>
                                                            </td>
                                                          </tr>
                                                        {/foreach}
                                                    </tbody>
                                                </table>
                                                </form>
                                                <div>
                                                    <div style="float:left;"><a href="javascript:void(0);" onclick="reback_select()" id="button-delete6" data-toggle="tooltip" title="删除" class="btn btn-danger" data-original-title="放入回收站">把选中文章放入回收站</a></div>
                                                    <div style="float:right;margin-top:-20px;" id="pagelist">{$page|raw}<span style="float:right;margin:25px">共{$total}条</span></div>
                                                </div>
                                                <script>
                                                    // 点击分页触发的事件
                                                    $(".pagination a").click(function(){
                                                        url = $(this).attr('href');
                                                        ajax_get_table('formSearch',url);
                                                        return false;
                                                    });
                                                    // 删除选中
                                                    function reback_select(){
                                                        parent.layer.confirm('确定把选中文章加入回收站？', function(){
                                                            url = window.location.href;
                                                            $.ajax({
                                                                url:"/index.php/Admin/article/reback_select",
                                                                data : $('#form-order').serialize(),
                                                                success: function(v){
                                                                    var v =  eval('('+v+')');
                                                                    parent.layer.msg(v.message, {icon: v.icon,time: 1000});
                                                                    if(v.hasOwnProperty('status') && (v.status == 1))
                                                                        getAjaxList('ajaxList',1,"/index.php/Admin/Article/ajaxArticleList");
                                                                }
                                                            });
                                                        });
                                                    }

                                                    function attrBg(obj){
                                                        if($(obj).prop('checked')){
                                                            $(obj).closest('tr').addClass('active_bg');
                                                        }else{
                                                            $(obj).closest('tr').removeClass('active_bg');
                                                        }
                                                    }
                                                </script>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<input id="handle_status" value="" hidden="hidden">
<input id="kind_id" value="0" hidden="hidden">
 
<script>
    function delarticle(obj,name,id,url) {
        top.layer.confirm(name,{
            icon : 3,
            btn:['确定','取消'],
        } , function(){
            $.ajax({
                url : url,
                type : "post",
                data : {article_id:id,act:'del'},
                dataType : "json",
                success:function(data){
                    if (data.status == 0) { 
                        top.layer.msg(data.message);
                    } else {
                        top.layer.msg(data.message);
                        $(obj).parent().parent().remove();
                    }
                }
            });
        } , function(){
            layer.close(); //再执行关闭 
        })
    }

    function copyarticle(obj,name,id,url) {
        top.layer.confirm(name,{
            icon : 3,
            btn:['确定','取消'],
        } , function(){
            $.ajax({
                url : url,
                type : "post",
                data : {article_id:id,act:'copy'},
                dataType : "json",
                success:function(data){
                    if (data.status == 0) { 
                        top.layer.msg(data.message);
                    } else {
                        top.layer.msg(data.message,{time:2000},function(){
                            window.location.href = location.href;
                        });
                    }
                }
            });
        } , function(){
            layer.close(); //再执行关闭 
        })
    }

    // getAjaxList('ajaxList',1,"/index.php/Admin/Article/ajaxArticleList");

    // ajax 抓取页面 form 为表单id  page 为当前第几页
    // function ajax_get_table(form,url){
    //     // cur_page = page; //当前页面 保存为全局变量
    //     // var info = $('#page_info').val();
    //     $.ajax({
    //         type : "POST",
    //         url:url,
    //         data : $('#'+form).serialize(),// 你的formid
    //         success: function(data){
    //             $("#ajaxList").html('');
    //             $("#ajaxList").append(data);
    //         }
    //     });
    //     return false;
    // }

    $(".kind_id").change(function(){
      var kind_id = $(this).val();
      $("#kind_id").val(kind_id);
    });
</script>

</body>

</html>